<?php
require_once('kernel.inc');

if($AUTH->logedstatus == false || $AUTH->permission != 'system') exit();

require_once(LIBRARIES.'/Sajax.php');
sajax_init();
sajax_export("GetInTree");
sajax_export("GetNode");
sajax_export("ProcessingData");
sajax_handle_client_request();

function GetInTree($id)
{
    $MECCANO = &$GLOBALS['MECCANO'];


    return $MECCANO->GetTree($id);
}

function GetNode($id)
{
    $MECCANO = &$GLOBALS['MECCANO'];

    return $MECCANO->GetNode($id);
}

function ProcessingData($str)
{
    $MECCANO = &$GLOBALS['MECCANO'];
    $exec_status = 0;

    if(get_magic_quotes_gpc())
    {
        $str = stripslashes($str);
    }
    $str = explode(':::', $str);

    foreach ($str as $var)
    {
        $var = explode('=', $var);
        isAlpha($var[0]);
        if($var[0] != false)
        {
            $$var[0] = $var[1];
        }
    }

    if(isset($id))      { isDigit($id); }                 else { $id = null; }
    if(isset($action))  { isAlpha(strtolower($action)); } else { $action = false; }
    if(isset($module))  { isAlpha(strtolower($module)); } else { $module = false; }
    //if(isset($notes))   { prepare_str($notes); }          else { $notes = null; }
    if($action != 'drop')
    {
        foreach ($MECCANO->system['lang'] as $lang)
        {
            $title[$lang] = ${'title_'.$lang};
            $notes[$lang] = ${'notes_'.$lang};
        }
    } else
    {
        $title = null;
    }

    $vars['notes']   = $notes;
    $vars['module']  = $module;
    $vars['title']   = $title;

    switch ($action)
    {
        case 'drop':
        $exec_status = $MECCANO->DropTree($id);
        break;

        case 'add':
        $exec_status = $MECCANO->AddNode($id, $vars);
        break;

        case 'edit':
        $exec_status = $MECCANO->UpdateNode($id, $vars);
        break;
    }

    if($exec_status != false)
    {
        return 1;
    } else
    {
        return 0;
    }
}
?>